using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AjaxControlToolkit;

namespace AjaxControlToolkit.Models.MSTest
{
	
	public partial class ReorderListItemCollectionTests
	{


        

		[TestMethod]
        public void ReorderListItemCollectionTests_ListT_ReorderListItem_Add ()
		{
			IList<AjaxControlToolkit.ReorderListItem> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            var oldCount = objectUnderTest.Count;
            AjaxControlToolkit.ReorderListItem newItem;

            try
            {
                newItem = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                objectUnderTest.Add(newItem);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            

            Assert.AreEqual(oldCount + 1, objectUnderTest.Count);
            Assert.IsTrue(objectUnderTest.Contains(newItem));

		}

		[TestMethod]
        public void ReorderListItemCollectionTests_ListT_ReorderListItem_AddClear ()
		{
			IList<AjaxControlToolkit.ReorderListItem> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            AjaxControlToolkit.ReorderListItem newItem;
            
            try
            {
                newItem = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                objectUnderTest.Add(newItem);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            
            Assert.IsTrue(objectUnderTest.Contains(newItem));

            objectUnderTest.Clear();
            Assert.AreEqual(0, objectUnderTest.Count);
            Assert.IsFalse(objectUnderTest.Contains(newItem));

		}

		[TestMethod]
        public void ReorderListItemCollectionTests_ListT_ReorderListItem_Clear ()
		{
			IList<AjaxControlToolkit.ReorderListItem> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;         

            objectUnderTest.Clear();
            Assert.AreEqual(0, objectUnderTest.Count);

		}


        [TestMethod]
        public void ReorderListItemCollectionTests_ListT_ReorderListItem_AddRemove ()
		{
			IList<AjaxControlToolkit.ReorderListItem> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            var oldCount = objectUnderTest.Count;
            
            AjaxControlToolkit.ReorderListItem newItem;

            try
            {
                newItem = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                objectUnderTest.Add(newItem);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            

            Assert.AreEqual(oldCount + 1, objectUnderTest.Count);
            Assert.IsTrue(objectUnderTest.Contains(newItem));

            objectUnderTest.Remove(newItem);
            
            Assert.AreEqual(oldCount, objectUnderTest.Count);
            Assert.IsFalse(objectUnderTest.Contains(newItem));
		}

        [TestMethod]
        public void ReorderListItemCollectionTests_ListT_ReorderListItem_AddRemoveAt ()
		{
			IList<AjaxControlToolkit.ReorderListItem> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            var oldCount = objectUnderTest.Count;
            AjaxControlToolkit.ReorderListItem newItem;

            try
            {
                newItem = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                objectUnderTest.Add(newItem);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            

            Assert.AreEqual(oldCount + 1, objectUnderTest.Count);
            Assert.IsTrue(objectUnderTest.Contains(newItem));

            var newIndex = objectUnderTest.IndexOf(newItem);
            objectUnderTest.RemoveAt(newIndex);
            
            Assert.AreEqual(oldCount, objectUnderTest.Count);
            Assert.IsFalse(objectUnderTest.Contains(newItem));
		}

        [TestMethod]
        public void ReorderListItemCollectionTests_ListT_ReorderListItem_InsertFirst ()
		{
			IList<AjaxControlToolkit.ReorderListItem> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            objectUnderTest.Clear();
            Assert.AreEqual(0, objectUnderTest.Count);

            AjaxControlToolkit.ReorderListItem newItem1;
            AjaxControlToolkit.ReorderListItem newItem2;
            AjaxControlToolkit.ReorderListItem newItem3;

            try
            {
                newItem1 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem2 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem3 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));

                objectUnderTest.Add(newItem1);
                objectUnderTest.Add(newItem2);
                objectUnderTest.Add(newItem3);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            

            Assert.AreEqual(3, objectUnderTest.Count);

            var testItem = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
            objectUnderTest.Insert(0, testItem);

            Assert.AreEqual(4, objectUnderTest.Count);
            Assert.AreEqual(0, objectUnderTest.IndexOf(testItem));                     
            Assert.IsTrue(objectUnderTest.Contains(testItem));
            
		}

        [TestMethod]
        public void ReorderListItemCollectionTests_ListT_ReorderListItem_InsertMiddle ()
		{
			IList<AjaxControlToolkit.ReorderListItem> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            objectUnderTest.Clear();
            Assert.AreEqual(0, objectUnderTest.Count);

            AjaxControlToolkit.ReorderListItem newItem1;
            AjaxControlToolkit.ReorderListItem newItem2;
            AjaxControlToolkit.ReorderListItem newItem3;

            try
            {
                newItem1 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem2 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem3 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));

                objectUnderTest.Add(newItem1);
                objectUnderTest.Add(newItem2);
                objectUnderTest.Add(newItem3);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            

            Assert.AreEqual(3, objectUnderTest.Count);

            var testItem = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
            objectUnderTest.Insert(2, testItem);

            Assert.AreEqual(4, objectUnderTest.Count);
            Assert.AreEqual(2, objectUnderTest.IndexOf(testItem));                     
            Assert.IsTrue(objectUnderTest.Contains(testItem));
            
		}

        [TestMethod]
        public void ReorderListItemCollectionTests_ListT_ReorderListItem_InsertLast ()
		{
			IList<AjaxControlToolkit.ReorderListItem> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            objectUnderTest.Clear();
            Assert.AreEqual(0, objectUnderTest.Count);

            AjaxControlToolkit.ReorderListItem newItem1;
            AjaxControlToolkit.ReorderListItem newItem2;
            AjaxControlToolkit.ReorderListItem newItem3;

            try
            {
                newItem1 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem2 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem3 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));

                objectUnderTest.Add(newItem1);
                objectUnderTest.Add(newItem2);
                objectUnderTest.Add(newItem3);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            

            Assert.AreEqual(3, objectUnderTest.Count);

            var testItem = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
            objectUnderTest.Insert(3, testItem);

            Assert.AreEqual(4, objectUnderTest.Count);
            Assert.AreEqual(3, objectUnderTest.IndexOf(testItem));                     
            Assert.IsTrue(objectUnderTest.Contains(testItem));
            
		}

        [TestMethod]
        public void ReorderListItemCollectionTests_ListT_ReorderListItem_CopyTo_Middle ()
		{
			IList<AjaxControlToolkit.ReorderListItem> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            objectUnderTest.Clear();
            Assert.AreEqual(0, objectUnderTest.Count);

            AjaxControlToolkit.ReorderListItem newItem1;
            AjaxControlToolkit.ReorderListItem newItem2;
            AjaxControlToolkit.ReorderListItem newItem3;

            try
            {
                newItem1 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem2 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem3 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));

                objectUnderTest.Add(newItem1);
                objectUnderTest.Add(newItem2);
                objectUnderTest.Add(newItem3);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            

            Assert.AreEqual(3, objectUnderTest.Count);

            var array = new AjaxControlToolkit.ReorderListItem[5];

            objectUnderTest.CopyTo(array, 1);

            Assert.AreEqual(default(AjaxControlToolkit.ReorderListItem), array[0]);
            Assert.AreEqual(newItem1, array[1]);
            Assert.AreEqual(newItem2, array[2]);
            Assert.AreEqual(newItem3, array[3]);
            Assert.AreEqual(default(AjaxControlToolkit.ReorderListItem), array[4]);
            
		}

        [TestMethod]
        public void ReorderListItemCollectionTests_ListT_ReorderListItem_CopyTo_Front ()
		{
			IList<AjaxControlToolkit.ReorderListItem> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            objectUnderTest.Clear();
            Assert.AreEqual(0, objectUnderTest.Count);

            AjaxControlToolkit.ReorderListItem newItem1;
            AjaxControlToolkit.ReorderListItem newItem2;
            AjaxControlToolkit.ReorderListItem newItem3;

            try
            {
                newItem1 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem2 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem3 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));

                objectUnderTest.Add(newItem1);
                objectUnderTest.Add(newItem2);
                objectUnderTest.Add(newItem3);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            

            Assert.AreEqual(3, objectUnderTest.Count);

            var array = new AjaxControlToolkit.ReorderListItem[5];

            objectUnderTest.CopyTo(array, 0);

            Assert.AreEqual(newItem1, array[0]);
            Assert.AreEqual(newItem2, array[1]);
            Assert.AreEqual(newItem3, array[2]);
            Assert.AreEqual(default(AjaxControlToolkit.ReorderListItem), array[3]);
            Assert.AreEqual(default(AjaxControlToolkit.ReorderListItem), array[4]);
            
		}

        [TestMethod]
        public void ReorderListItemCollectionTests_ListT_ReorderListItem_CopyTo_End ()
		{
			IList<AjaxControlToolkit.ReorderListItem> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            objectUnderTest.Clear();
            Assert.AreEqual(0, objectUnderTest.Count);

            AjaxControlToolkit.ReorderListItem newItem1;
            AjaxControlToolkit.ReorderListItem newItem2;
            AjaxControlToolkit.ReorderListItem newItem3;

            try
            {
                newItem1 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem2 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem3 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));

                objectUnderTest.Add(newItem1);
                objectUnderTest.Add(newItem2);
                objectUnderTest.Add(newItem3);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            

            Assert.AreEqual(3, objectUnderTest.Count);

            var array = new AjaxControlToolkit.ReorderListItem[5];

            objectUnderTest.CopyTo(array, 2);

            Assert.AreEqual(default(AjaxControlToolkit.ReorderListItem), array[0]);
            Assert.AreEqual(default(AjaxControlToolkit.ReorderListItem), array[1]);
            Assert.AreEqual(newItem1, array[2]);
            Assert.AreEqual(newItem2, array[3]);
            Assert.AreEqual(newItem3, array[4]);            
		}

        [TestMethod]
        public void ReorderListItemCollectionTests_ListT_ReorderListItem_CopyTo_Full ()
		{
			IList<AjaxControlToolkit.ReorderListItem> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            objectUnderTest.Clear();
            Assert.AreEqual(0, objectUnderTest.Count);

            AjaxControlToolkit.ReorderListItem newItem1;
            AjaxControlToolkit.ReorderListItem newItem2;
            AjaxControlToolkit.ReorderListItem newItem3;

            try
            {
                newItem1 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem2 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem3 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));

                objectUnderTest.Add(newItem1);
                objectUnderTest.Add(newItem2);
                objectUnderTest.Add(newItem3);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            

            Assert.AreEqual(3, objectUnderTest.Count);

            var array = new AjaxControlToolkit.ReorderListItem[3];

            objectUnderTest.CopyTo(array, 0);

            Assert.AreEqual(newItem1, array[0]);
            Assert.AreEqual(newItem2, array[1]);
            Assert.AreEqual(newItem3, array[2]);
            
		}

        [TestMethod]
        public void ReorderListItemCollectionTests_ListT_ReorderListItem_CopyTo_TooSmall ()
		{
			IList<AjaxControlToolkit.ReorderListItem> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            objectUnderTest.Clear();
            Assert.AreEqual(0, objectUnderTest.Count);

            AjaxControlToolkit.ReorderListItem newItem1;
            AjaxControlToolkit.ReorderListItem newItem2;
            AjaxControlToolkit.ReorderListItem newItem3;

            try
            {
                newItem1 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem2 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem3 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));

                objectUnderTest.Add(newItem1);
                objectUnderTest.Add(newItem2);
                objectUnderTest.Add(newItem3);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            

            Assert.AreEqual(3, objectUnderTest.Count);

            var array = new AjaxControlToolkit.ReorderListItem[2];

            try
            {
                objectUnderTest.CopyTo(array, 0);
                Assert.Fail("This should have thrown an exception.");
            }
            catch (ArgumentException)
            {
                //OK
            }

            //make sure nothing was over-written
            Assert.AreEqual(default(AjaxControlToolkit.ReorderListItem), array[0]);
            Assert.AreEqual(default(AjaxControlToolkit.ReorderListItem), array[1]);
		}

        [TestMethod]
        public void ReorderListItemCollectionTests_ListT_ReorderListItem_CopyTo_PastEnd ()
		{
			IList<AjaxControlToolkit.ReorderListItem> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            objectUnderTest.Clear();
            Assert.AreEqual(0, objectUnderTest.Count);

            AjaxControlToolkit.ReorderListItem newItem1;
            AjaxControlToolkit.ReorderListItem newItem2;
            AjaxControlToolkit.ReorderListItem newItem3;

            try
            {
                newItem1 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem2 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem3 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));

                objectUnderTest.Add(newItem1);
                objectUnderTest.Add(newItem2);
                objectUnderTest.Add(newItem3);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            

            Assert.AreEqual(3, objectUnderTest.Count);

            var array = new AjaxControlToolkit.ReorderListItem[3];

            try
            {
                objectUnderTest.CopyTo(array, 1);
                Assert.Fail("This should have thrown an exception");
            }
            catch (ArgumentException)
            {
                //OK
            }

            //make sure nothing was over-written
            Assert.AreEqual(default(AjaxControlToolkit.ReorderListItem), array[0]);
            Assert.AreEqual(default(AjaxControlToolkit.ReorderListItem), array[1]);
            Assert.AreEqual(default(AjaxControlToolkit.ReorderListItem), array[2]);

		}

        [TestMethod]
        public void ReorderListItemCollectionTests_ListT_ReorderListItem_CopyTo_OOR ()
		{
			IList<AjaxControlToolkit.ReorderListItem> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            objectUnderTest.Clear();
            Assert.AreEqual(0, objectUnderTest.Count);

            AjaxControlToolkit.ReorderListItem newItem1;
            AjaxControlToolkit.ReorderListItem newItem2;
            AjaxControlToolkit.ReorderListItem newItem3;

            try
            {
                newItem1 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem2 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem3 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));

                objectUnderTest.Add(newItem1);
                objectUnderTest.Add(newItem2);
                objectUnderTest.Add(newItem3);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            

            Assert.AreEqual(3, objectUnderTest.Count);

            var array = new AjaxControlToolkit.ReorderListItem[3];

            try
            {
                objectUnderTest.CopyTo(array, -1);
                Assert.Fail("This should have thrown an exception.");
            }
            catch (ArgumentOutOfRangeException)
            {
                //OK
            }

            //make sure nothing was over-written
            Assert.AreEqual(default(AjaxControlToolkit.ReorderListItem), array[0]);
            Assert.AreEqual(default(AjaxControlToolkit.ReorderListItem), array[1]);
            Assert.AreEqual(default(AjaxControlToolkit.ReorderListItem), array[2]);
            
            
		}

        [TestMethod]
        public void ReorderListItemCollectionTests_ListT_ReorderListItem_CopyTo_Null ()
		{
			IList<AjaxControlToolkit.ReorderListItem> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            objectUnderTest.Clear();
            Assert.AreEqual(0, objectUnderTest.Count);

            AjaxControlToolkit.ReorderListItem newItem1;
            AjaxControlToolkit.ReorderListItem newItem2;
            AjaxControlToolkit.ReorderListItem newItem3;

            try
            {
                newItem1 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem2 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));
                newItem3 = new AjaxControlToolkit.ReorderListItem(default(System.Int32));

                objectUnderTest.Add(newItem1);
                objectUnderTest.Add(newItem2);
                objectUnderTest.Add(newItem3);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            

            Assert.AreEqual(3, objectUnderTest.Count);

            try
            {
                objectUnderTest.CopyTo(null, -1);
                Assert.Fail("This should have thrown an exception.");
            }
            catch (ArgumentNullException)
            {
                //OK
            }

		}




        
	}
}

